package com.jhw.ymcc.controller;

import com.jhw.doc.CourseDoc;
import com.jhw.ymcc.dto.CourseEsDto;
import com.jhw.ymcc.result.JSONResult;
import com.jhw.ymcc.result.PageList;
import com.jhw.ymcc.service.ICourseEsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author jhw
 * @create 2022/10/12
 */
@RestController
@RequestMapping("/course")
public class CourseEsController {

    @Autowired
    private ICourseEsService courseEsService;
    // 保存课到es
    @PostMapping("/saveCourseEs")
    public JSONResult saveCourseEs(@RequestBody CourseDoc courseDoc){
        courseEsService.save(courseDoc);
        return JSONResult.success();
    }

    // 删除es的课程
    @DeleteMapping("/delCourseEs")
    public JSONResult delCourseEs(@RequestBody CourseDoc courseDoc){
        courseEsService.del(courseDoc);
        return JSONResult.success();
    }

    @PostMapping("/search")
    public JSONResult search(@RequestBody CourseEsDto courseEsDto){
        PageList<CourseDoc> pageList = courseEsService.search(courseEsDto);
        return JSONResult.success(pageList);
    }

}
